import buy.ShoppingCart;
import fruit.Fruit;

import java.math.BigDecimal;

public class SupermarketSystem {
    // 顾客A (苹果和草莓，无促销)
    public static BigDecimal calculateTotalForA(int appleKg, int strawberryKg) {
        ShoppingCart cart = new ShoppingCart();
        cart.addFruit(Fruit.apple(), appleKg);
        cart.addFruit(Fruit.strawberry(), strawberryKg);
        return cart.calculateTotal();
    }

    // 顾客B (增加芒果，无促销)
    public static BigDecimal calculateTotalForB(int appleKg, int strawberryKg, int mangoKg) {
        ShoppingCart cart = new ShoppingCart();
        cart.addFruit(Fruit.apple(), appleKg);
        cart.addFruit(Fruit.strawberry(), strawberryKg);
        cart.addFruit(Fruit.mango(), mangoKg);
        return cart.calculateTotal();
    }

    // 顾客C (草莓8折)
    public static BigDecimal calculateTotalForC(int appleKg, int strawberryKg, int mangoKg) {
        ShoppingCart cart = new ShoppingCart();
        cart.addFruit(Fruit.apple(), appleKg);
        cart.addFruit(Fruit.mango(), mangoKg);

        Fruit strawberry = Fruit.strawberry();
        cart.addFruit(strawberry, strawberryKg);
        cart.setPromotionStrategy(original -> {
            BigDecimal strawberryCost = strawberry.calculateCost(strawberryKg);
            BigDecimal discount = strawberryCost.multiply(BigDecimal.valueOf(0.2));
            return original.subtract(discount);
        });

        return cart.calculateTotal();
    }

    // 顾客D (草莓8折 + 满100减10)
    public static BigDecimal calculateTotalForD(int appleKg, int strawberryKg, int mangoKg) {
        ShoppingCart cart = new ShoppingCart();
        cart.addFruit(Fruit.apple(), appleKg);
        cart.addFruit(Fruit.mango(), mangoKg);

        Fruit strawberry = Fruit.strawberry();
        cart.addFruit(strawberry, strawberryKg);
        cart.setPromotionStrategy(original -> {
            BigDecimal strawberryCost = strawberry.calculateCost(strawberryKg);
            // 草莓8折
            BigDecimal discountedPrice = original.subtract(strawberryCost.multiply(BigDecimal.valueOf(0.2)));
            // 满100减10
            if (discountedPrice.compareTo(BigDecimal.valueOf(100)) >= 0) {
                return discountedPrice.subtract(BigDecimal.valueOf(10));
            } else {
                return discountedPrice;
            }
        });

        return cart.calculateTotal();
    }
}
